/**
 * 匹配当前路由最顶级路由
 * @param 被查路由列表 data 
 * @param 当前最子孙路由 path 
 * @returns 
 */
export function getRouteInfo(data, path) {
    const getLeftMenuList = (data) => {
        const findParent = (list, letMenuPath) => {
            for (let i = 0; i < list.length; i++) {
                list[i]['letMenuPath'] = letMenuPath
                if (list[i]['children']) {
                    list[i]['children'] = findParent(list[i]['children'], letMenuPath)
                }
            }
            return list
        }

        for (let i = 0; i < data.length; i++) {
            data[i]['letMenuPath'] = data[i]['path']
            if (data[i]['children']) {
                data[i]['children'] = findParent(data[i]['children'], data[i]['path'])
            }
        }
        return data
    }
    const menuList = getLeftMenuList(data);

    // 多维数组变一维数组
    var newData = []
    const findChildren = (list) => {
        for (let i = 0; i < list.length; i++) {
            newData.push(list[i])
            if (list[i].children) {
                list[i]['children'] = findChildren(list[i].children)
            }
        }
    }
    for (let i = 0; i < menuList.length; i++) {
        newData.push(menuList[i])
        if (menuList[i].children) {
            findChildren(menuList[i].children)
        }
    }
    // 匹配当前路由信息
    let letMenuPath = ''
    for (let i = 0; i < newData.length; i++) {
        if (newData[i]['path'] == path) {
            letMenuPath = newData[i]['letMenuPath']
        }
    }
    return letMenuPath
}